import 'dart:ui';

import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:search_people/page/analysis/main/widgets/widgets.dart';

import 'index.dart';
import 'widgets/widgets.dart';

class TrdTouchPage extends GetView<TrdTouchController> {
  const TrdTouchPage({Key? key}) : super(key: key);

  // 主视图
  Widget _buildView() {
    var state = controller.state;
    Get.log(state.scale.toString());
    return Container(
      margin: EdgeInsets.only(left: state.offset?.dx ?? 0),
      width: state.size?.width,
      height: state.size?.height,
      child: Transform.scale(
        scale: state.scale,
        child: AnalysisCell(
          md: state.md!,
        ),
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return GetBuilder<TrdTouchController>(
      builder: (_) {
        var state = controller.state;
        return Scaffold(
          backgroundColor: Colors.transparent,
          body: GestureDetector(
            onTap: () {
              controller.actionDismiss();
            },
            behavior: HitTestBehavior.opaque,
            child: Stack(
              children: [
                state.isShowBlur
                    ? BackdropFilter(
                        filter: ImageFilter.blur(sigmaX: 10, sigmaY: 10),
                        child: SizedBox(
                          height: 1.sh,
                        ),
                      )
                    : SizedBox(
                        height: 1.sh,
                      ),
                Container(
                  height: 50.r,
                  width: 1.sw,
                ),
                Positioned(
                  top: state.offset?.dy ?? 0,
                  child: _buildView(),
                ),
                Positioned(
                  top: state.oprationOffset.dy,
                  left: state.oprationOffset.dx,
                  child: Visibility(
                    visible: state.isShowBlur,
                    child: TouchOprationWidget(),
                  ),
                ),
              ],
            ),
          ),
        );
      },
    );
  }
}
